package com.service.impl;

import com.entity.User;
import com.esDao.EmpDao;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.UserMapper;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private EmpDao empDao;
    @Override
    public void addUser(User user) {
        //除了往mysql中添加数据，还要往es中添加数据
        userMapper.insertUser(user);
        empDao.insertUser(user);
    }

    @Override
    public void removeUserById(Integer id) {
        userMapper.deleteUserById(id);
        empDao.deleteUserById(id);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
        empDao.updateUser(user);
    }

    @Override
    public User showUserById(Integer id) {
        return userMapper.selectUserById(id);
    }

    @Override
    public List<User> showUser() {
        return userMapper.selectUser();
    }

    @Override
    public PageInfo<User> showPageUser(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(userMapper.selectUser());
    }
}
